<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>vue源码解析</title>
	<script src="./vue.js"></script>
</head>
<body>
	<script>
		// 1.symbol类型
		var sym = Symbol('foo');
		var obj = {[sym] : 1};
		console.log(obj[sym] === 1) //true

		var sym2 = Symbol('foo');
		console.log(sym == sym2) //false
		// 2.cached方式加快数据的读取速度，加做缓存策略
		 function cached (fn) {
		 	var cache = Object.create(null);
		 	return (function cachedFn (str) { // 闭包
		 	console.log('cache' ,cache); //将变量驻留在内存中
		 	var hit = cache[str]; //以函数的参数为键
		 	//如果缓存对象中存在这个键，那么就从缓存中返回这个函数
		 	//如果没有就把这个函数赋值到缓存对象中并且返回
		 	return hit || (cache[str] = fn(str))
		 })}

		var fk = function (str) {  // 复杂计算  用来感受cached的缓存策略
			console.log('a')
		 	return str.charAt(0).toUpperCase() + str.slice(1)
		}
		 var checkFk = cached(fk)
		 console.log(checkFk('ui'))

		 console.log(checkFk('ui'))


		 function once (fn) {
		 	var called = false;
		 	return function () {
		 		if (!called) {
		 			called = true;
		 			console.log('arguments[1]', arguments[1])
		 			fn.apply(this, arguments);
		 		}
		 	}
		 }

		 var ca = once(function(a, b, c) {
		 	console.log('arguments[0]' ,arguments[0])
		 })
		 // console.log('called', called) // not defined
		 ca(1, 2, 3)
		 ca(4, 5, 6) // 将不执行


        // 正则表达式的source属性
        var str="This is an good antzone";
        var reg=/an/g;
        console.log('reg.source', reg.source);


         var repeat = function (str, n) {
            var res = '';
            while (n) {
                if (n % 2 === 1) { //%在JS中表示取余数
                    res += str;
                }
                if (n > 1) {
                    str += str;
                }
                console.log('>>>>' ,n >> 1)
                n >>= 1;
                console.log(n)
                //16 8
                //15 7 相当于除2 向下取整2的倍数
                //console.log(  a >>= 1)
            }
            return res
        };
        console.log(repeat('lican', 30))

        var uid = 0;
        var Dep = function Dep () {
            this.id = uid++;
            this.subs = [];
        };
        Dep()
	</script>
</body>
</html>